package com.zsx.utils;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class C3p0Util {
    private static ComboPooledDataSource sc;
    private static Connection conn;
    private static Statement statement;
    private static ResultSet resultSet;
    static{
        sc=new ComboPooledDataSource();//不传参默认使用第一个配置，传参使用指定配置
        try {
            conn=sc.getConnection();
            statement= conn.createStatement();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
    public static Statement getStatement(){
        return statement;
    }

    //关闭结果集，sql执行对象，连接
    public static void close(){
        if (resultSet!=null){
            try {
                resultSet.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        if(statement!=null){
            try {
                statement.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        if(conn!=null){
            try {
                conn.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
    }

}
